package cn.yunbamboos.rest.service.logs;

import cn.hutool.core.collection.CollectionUtil;
import cn.yunbamboos.rest.service.logs.event.LogEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

public class LogMetadataManager {

    private final List<IStorageLogListener> listeners;

    public LogMetadataManager(List<IStorageLogListener> listeners){
        this.listeners = listeners;
    }

    /**
     * 储存日志事件
     * */
    @Async("TaskExecutor")
    @EventListener
    public void onApplicationEvent(LogEvent event) {
        event.log();
        if(CollectionUtil.isNotEmpty(listeners)){
            for(IStorageLogListener listener: listeners){
                listener.storage(event);
            }
        }
    }

}
